package client.comm.baoding.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.comm.baoding.api.bean.CateGoods
import client.comm.baoding.api.bean.TdBean
import client.comm.baoding.api.bean.UserInfo
import client.comm.baoding.ui.viewmodel.MiddleVm
import client.comm.commlib.network.data.JsonResult
import client.comm.commlib.network.data.Ret
import client.comm.commlib.utils.StoreUtil

class GylViewModel(app: Application) : MiddleVm(app) {

    val isShowing = MutableLiveData<Boolean>(false)

    val callUser = MutableLiveData<JsonResult<UserInfo>>()

    val delRet = MutableLiveData<JsonResult<Ret>>()

    val tradeCall = MutableLiveData<JsonResult<CateGoods>>()


    //分页
    val isOneLoading = MutableLiveData<Boolean>(false)
    val callTd = MutableLiveData<JsonResult<UserInfo>>()

    val pageOne = MutableLiveData<Int>(0)

    val callOne = MutableLiveData<JsonResult<TdBean>>()
    val startCall = MutableLiveData<JsonResult<Ret>>()
    val isSign = MutableLiveData<Boolean>(false)


    fun userInfo() {
        hold({
            server.userinfo().apply {
                body()?.let {
                    if (it.isSuccess) {
                        StoreUtil.saveBean(getApplication(), it.data!!)
                    }
                }
            }
        }, success = {
            callUser.value = it
            callTd.value = it
        })
    }


    fun start() {
        isShowing.value = true
        isSign.value = true
        hold({
            server.user_sign_in()
        }, success = {
            startCall.value = it
        }, complete = {
            isShowing.value = false
        }, err = {
            isSign.value = false
        })
    }



}